package com.wiki4j.gdo.impl;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.wiki4j.gdo.GDOType;
import com.wiki4j.gdo.GDProperty;
import com.wiki4j.gdo.GDType;
import com.wiki4j.gdo.type.GDTypeBase;

//@JSONType(serializer=GDPropertySerializer.class)
public class GDPropertyImpl implements GDProperty{
  private String name;
  private int arrayDim;
  //  @JSONField(serializeUsing=GDTypeSerializer.class,deserializeUsing=GDTypeDeserializer.class)
  @JsonDeserialize
  private GDType type;

  public GDPropertyImpl(String name,GDType type,int arrayDim){
    this.name=name;
    this.type=type;
    this.arrayDim=arrayDim;
  }

  @Override
  public GDType getType(){
    return type;
  }

  @Override
  public GDTypeBase baseType(){
    if(!(type instanceof GDTypeBase)) throw new IllegalArgumentException("Property: "+name+" is not base type!");
    return (GDTypeBase)type;
  }

  @Override
  public GDOType gdoType(){
    if(!(type instanceof GDOType)) throw new IllegalArgumentException("Property: "+name+" is not gdo type!");
    return (GDOType)type;
  }

  @Override
  public int getArrayDim(){
    return arrayDim;
  }
}
